package wta.cloud.action;


import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import wta.cloud.dao.CancerDao;
import wta.cloud.entity.Cancer;
import wta.cloud.service.NeuralNetwork;

@Controller
public class CancerAction {
	
	@Resource
	private CancerDao cancerDao;
	
	@RequestMapping(value="/aizdresult", method=RequestMethod.GET)
	public String queryCancer(Model model,String name, String uid){
		Cancer cancer = cancerDao.getCancer(uid);
		double p = NeuralNetwork.NN(new double[][] 
				{{cancer.getSex(),			cancer.getAge(),  	cancer.getBMI(),  	cancer.getShousuoya(),
				  cancer.getShuzhangya(),	cancer.getWBC(),  	cancer.getRBC(),  	cancer.getHGB(),
				  cancer.getHCT(),  		cancer.getMCV(),  	cancer.getMCH(),  	cancer.getMCHC(),
				  cancer.getRDWCV(),  		cancer.getRDWSD(),  cancer.getPLT(), 	cancer.getMPV(),
				  cancer.getPDW(),  		cancer.getMON(),  	cancer.getMON_(),  	cancer.getGRA_(),
				  cancer.getLYM_(),  		cancer.getGRA(),  	cancer.get_LYM(),  	cancer.getALT(),
				  cancer.getUREA(),  		cancer.getCR(),  	cancer.getUA(),  	cancer.getTC(),
				  cancer.getTG(),  			cancer.getFPG(),  	cancer.getSG(),  	cancer.getpH()}} );
	
		model.addAttribute("name", name);
		model.addAttribute(cancer);
		model.addAttribute("p", (double)(Math.round(p*100)/100.0));

		Double hct;
		if (cancer.getSex()==0){ //男
			hct = 200+200*(cancer.getHCT() -40 )/(54 - 40);
		}
		else{//女
			hct = 200+200*(cancer.getHCT() -35 )/(48 - 35);	
		}
		Double mcv = 200+200*(cancer.getMCV() -80 )/(97 - 80);
		Double mchc = 200+200*(cancer.getMCHC() -315 )/(360 - 315);
		Double rdwsd = 200+200*(cancer.getRDWSD() -40 )/(53 - 40);
		Double mpv = 200+200*(cancer.getMPV() -6.5 )/(12.5 - 6.5);
		Double mon = 200+200*(cancer.getMON() -2 )/(12 - 2);
		Double _lym = 200+200*(cancer.get_LYM() - 17.5 )/(48 - 17.5);
		Double fpg = 200+200*(cancer.getFPG() -3.6 )/(6.11 - 3.6);
		Double sg = 200+200*(cancer.getSG() -1.004 )/(1.03 - 1.004);
		model.addAttribute("hct",hct);
		model.addAttribute("mcv",mcv);
		model.addAttribute("mchc",mchc);
		model.addAttribute("rdwsd",rdwsd);
		model.addAttribute("mpv",mpv);
		model.addAttribute("mon",mon);
		model.addAttribute("_lym",_lym);	
		model.addAttribute("fpg",fpg);
		model.addAttribute("sg",sg);
		
		
		
		return "aizdresult";
	}
}
